package lib.pacificapp.ex.weixin.api; 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
  
import com.tencent.mm.sdk.openapi.BaseReq;
import com.tencent.mm.sdk.openapi.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.SendAuth;
public abstract class WeixinApi  extends Activity implements IWXAPIEventHandler {
		 /**微信登录回掉*/
		abstract public void onGetCodeComplete(String code); 
		abstract public void onError(); 
	    @Override
		    protected void onCreate(Bundle savedInstanceState) {
		        super.onCreate(savedInstanceState);

		        handleIntent(getIntent());
		    }

		    @Override
		    protected void onNewIntent(Intent intent) {
		        super.onNewIntent(intent);
		        handleIntent(intent);
		    }

		    private void handleIntent(Intent intent) {
		        SendAuth.Resp resp = new SendAuth.Resp(intent.getExtras());
		     
		        if (resp.errCode == BaseResp.ErrCode.ERR_OK) {
		        	 Log.d("debug",resp.token);  
		        	  onGetCodeComplete(resp.token);
		        }else{
		        	 onError();
		        } 
		        
		       
		    }

			@Override
			public void onReq(BaseReq arg0) {
				// TODO Auto-generated method stub
				 
			}

			@Override
			public void onResp(BaseResp resp) {
				Log.d("debug2",String.valueOf(resp.errCode)); 
				 
			}
		}
		 

	 